package com.example.sup.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.sup.aspect.annotation.CheckLogin;
import com.example.sup.controller.request.DistrictPrisonRequest;
import com.example.sup.controller.response.ServerResponse;
import com.example.sup.entity.PrisonDistrict;
import com.example.sup.entity.UserInfo;
import com.example.sup.service.PrisonDistrictService;
import com.example.sup.service.PrisonService;
import com.example.sup.vo.PrisonDistrictComboBoxVO;
import com.example.sup.vo.PrisonDistrictVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName PrisonDistrictController
 * @Description {TODO}
 * @Author 李哲
 * @Date 17:19 2024/7/23
 * @Version 1.0
 */
@RestController
@Slf4j
@RequestMapping("/prisonDistrict")
public class PrisonDistrictController {

    @Resource
    private PrisonDistrictService districtService;

    @Resource
    private PrisonService prisonService;


    @PostMapping("/query")
    public ServerResponse<Page<PrisonDistrict>> query() {
        //1.校验参数
        //2.调用service
        Page <PrisonDistrict> request = new Page<>();
        Page <PrisonDistrict> pageResult = districtService.page(request);
        //3.返回结果
        return ServerResponse.successWithMsg("操作成功",pageResult);
    }

    @PostMapping("/queryComboBox")
    public ServerResponse<List<PrisonDistrictComboBoxVO>> queryComboBox() {
        //1.校验参数
        //2.调用service
        List<PrisonDistrictComboBoxVO> voList = districtService.getPrisonDistrictsWithPrisons();
        //3.返回结果
        return ServerResponse.successWithMsg("操作成功",voList);
    }

    @PostMapping("queryPrison")
    @CheckLogin
    public ServerResponse queryPrison(UserInfo userInfo,
                                      @RequestBody @Validated DistrictPrisonRequest districtPrisonRequest){
        //1.参数校验
        log.info("登录的用户信息:{}",userInfo);
        //2.调用service返回vo
        List<PrisonDistrictVO> prisonDistrictVOList =  prisonService.queryPrisonByDistrictId(userInfo,districtPrisonRequest);
        //3.返回model---vo

        return ServerResponse.success(prisonDistrictVOList);
    }


}
